<?php

namespace XWAM\Controller;

/**
 * 验证码设置 控制器
 *
 * @since 1.0 <2017-3-24> SoChishun <14507247@qq.com> Added.
 */
class CaptchaSetting extends AppbaseController {

    // 2017-3-24
    public function editView($title) {
        $where = array('title' => 'CaptchaSetting-' . $title, 'conf_group' => 'CaptchaSetting');
        $mDict = new \XWAM\Model\UserDictModel();
        $data = $mDict->where($where)->find();
        if (!$data) {
            $mDict->add($where);
            $data = $mDict->where($where)->find();
        }
        if (!$data) {
            exit('数据库错误!');
        }
        $this->assign('data', $data);
        $this->assign('tabs', $this->getTabs());
        $this->display();
    }

    public function edit() {
        $this->editView('Regist');
    }

    public function login() {
        $this->editView('Login');
    }

    public function post() {
        $this->editView('Post');
    }

    public function reply() {
        $this->editView('Reply');
    }

    public function comment() {
        $this->editView('Comment');
    }

    public function getpassword() {
        $this->editView('Getpassword');
    }

    public function form() {
        $this->editView('Form');
    }

    public function customize() {
        $this->editView('Customize');
    }

    public function editSave() {
        $mDict = new \XWAM\Model\SensitiveWordsModel();
        $result = $mDict->saveConf();
        $this->dialogJump($result['status'], $result['info']);
    }

    // 2017-3-23
    protected function getTabs($name = '') {
        if (!$name) {
            $name = ACTION_NAME;
        }
        $data = array(
            'edit' => array('title' => '注册验证码', 'url' => 'edit', 'active' => ''),
            'login' => array('title' => '登录验证码', 'url' => 'login', 'active' => ''),
            'post' => array('title' => '发帖验证码', 'url' => 'post', 'active' => ''),
            'reply' => array('title' => '回帖验证码', 'url' => 'reply', 'active' => ''),
            'comment' => array('title' => '评论验证码', 'url' => 'comment', 'active' => ''),
            'getpassword' => array('title' => '找回密码验证码', 'url' => 'getpassword', 'active' => ''),
            'form' => array('title' => '前台表单验证码', 'url' => 'form', 'active' => ''),
            'customize' => array('title' => '自定义验证码', 'url' => 'customize', 'active' => ''),
        );
        if (array_key_exists($name, $data)) {
            $data[$name]['active'] = 'active';
        }
        return $data;
    }

}
